package com.wanbatv.wangwangba.Pager;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.wanbatv.wangwangba.Login2Activity;
import com.wanbatv.wangwangba.R;
import com.wanbatv.wangwangba.util.FocusImageView;

/**
 * Created by 俞亚楠 on 2015/8/26.
 */
public class page1 extends RelativeLayout{
    private Context context;
    private AttributeSet attrs;

    public static FocusImageView tuijian_iv1;
    public static FocusImageView tuijian_iv2;
    public static FocusImageView tuijian_iv3;
    public static FocusImageView tuijian_iv4;
    public static FocusImageView tuijian_iv5;
    public static ImageView tuijian_iv6;
    public static ImageView tuijian_iv7;
    public static ImageView tuijian_iv8;
    public static ImageView tuijian_iv9;
    public static boolean IS_F1=false;
    public page1(Context context){
        super(context);
        this.context=context;
    }
    public page1(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context=context;
        this.attrs=attrs;

        LayoutInflater.from(context).inflate(R.layout.page1_view, this, true);

        tuijian_iv1=(FocusImageView)findViewById(R.id.tuijian_iv1);
        tuijian_iv2=(FocusImageView)findViewById(R.id.tuijian_iv2);
        tuijian_iv3=(FocusImageView)findViewById(R.id.tuijian_iv3);
        tuijian_iv4=(FocusImageView)findViewById(R.id.tuijian_iv4);
//        tuijian_iv5=(FocusImageView)findViewById(R.id.tuijian_iv5);
        tuijian_iv6=(ImageView)findViewById(R.id.tuijian_iv6);
        tuijian_iv7=(ImageView)findViewById(R.id.tuijian_iv7);
        tuijian_iv8=(ImageView)findViewById(R.id.tuijian_iv8);
        tuijian_iv9=(ImageView)findViewById(R.id.tuijian_iv9);
        tuijian_iv1.setOnFocusChangeListener(new OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                image_fangda(v,hasFocus);
                Login2Activity.IS_SHANG=false;
                IS_F1=true;
                page2.IS_F2=false;
                page3.IS_F3=false;
                page4.IS_F4=false;
                page5.IS_F5=false;
                image_fangda(tuijian_iv6,true);
                if(!hasFocus){
                    image_fangda(tuijian_iv6,false);
                }
            }
        });
        tuijian_iv2.setOnFocusChangeListener(new OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                image_fangda(v,hasFocus);
                Login2Activity.IS_SHANG=false;
                IS_F1=true;
                page2.IS_F2=false;
                page3.IS_F3=false;
                page4.IS_F4=false;
                page5.IS_F5=false;
                image_fangda(tuijian_iv7,true);
                if(!hasFocus){
                    image_fangda(tuijian_iv7,false);
                }

            }
        });
        tuijian_iv3.setOnFocusChangeListener(new OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                image_fangda(v,hasFocus);
                Login2Activity.IS_SHANG=false;
                IS_F1=true;
                page2.IS_F2=false;
                page3.IS_F3=false;
                page4.IS_F4=false;
                page5.IS_F5=false;
                image_fangda(tuijian_iv8,true);
                if(!hasFocus){
                    image_fangda(tuijian_iv8,false);
                }

            }
        });
        tuijian_iv4.setOnFocusChangeListener(new OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                image_fangda(v,hasFocus);
                Login2Activity.IS_SHANG=false;
                IS_F1=false;
                page2.IS_F2=false;
                page3.IS_F3=false;
                page4.IS_F4=false;
                page5.IS_F5=false;
                image_fangda(tuijian_iv9,true);
                if(!hasFocus){
                    image_fangda(tuijian_iv9,false);
                }

            }
        });
//        tuijian_iv5.setOnFocusChangeListener(new OnFocusChangeListener() {
//            @Override
//            public void onFocusChange(View v, boolean hasFocus) {
//                image_fangda(v,hasFocus);
//                Login2Activity.IS_SHANG=false;
//                IS_F1=false;
//                page3.IS_F3=false;
//                page4.IS_F4=false;
//                page5.IS_F5=false;
//
//            }
//        });

    }
    public void image_fangda(View v, boolean hasFocus){
        if (hasFocus) {
            v.getParent().bringChildToFront(v);

            Animation ani = AnimationUtils.loadAnimation(v.getContext(),
                    R.anim.bar_scale);
            ani.setFillAfter(true);

            v.startAnimation(ani);


        } else {
            Animation ani = AnimationUtils.loadAnimation(v.getContext(),
                    R.anim.bar_scale_in);
            ani.setFillAfter(true);
            v.startAnimation(ani);

        }
    }


}
